var page = sm("do_Page");
var global = sm("do_Global");

var layoutZH = ui("layoutZH"),layoutDQ = ui("layoutDQ"),layoutHT = ui("layoutHT"),layoutCY = ui("layoutCY");
var layoutArr = [layoutZH,layoutDQ,layoutHT,layoutCY];
var btnZH = ui("btnZH"),btnDQ = ui("btnDQ"),btnHT = ui("btnHT"),btnCY = ui("btnCY");
var btnArr = [btnZH,btnDQ,btnHT,btnCY];
var line0 = ui("line0"),line1 = ui("line1"),line2 = ui("line2"),line3 = ui("line3");
var lineArr = [line0,line1,line2,line3];
var sortBg = ui("sortBg");
var sortArr = ["source://image/common/sort.png","source://image/common/sort01.png","source://image/common/sort02.png"];
var indexObj = {
	index: 0,
	sort:false,
	init:function(){
		indexObj.tab();
	},
	tab:function(){
		layoutArr.forEach(function(obj, i) {
			obj.on("touch", function(data, e) {
				indexObj.index = i;
				page.fire("getTabList",{index:i,sort:indexObj.sort}); //设置tab
				if(i != 3){
					indexObj.sort = false;
				}
				if(i == 1){
					page.fire("regionPageShow");
				}
				else if(i == 2){
					page.fire("topicPageShow");
				}
			});
		});
	},
	tabStyle:function(_index){
		indexObj.index = _index;
		if(_index == 3){
			indexObj.sort = !indexObj.sort;
			sortBg.source = indexObj.sort?sortArr[2]:sortArr[1];
		}else{
			sortBg.source = sortArr[0];
			indexObj.sort = false;
		}		
		for(var i = 0; i < 4; i++){
			btnArr[i].fontColor = "333333FF";
			lineArr[i].bgColor = "00000000";
		}
		btnArr[_index].fontColor = "F36F20FF";
		lineArr[_index].bgColor = "F36F20FF";
	}
}
indexObj.init();

page.on("setTabIndex",function(data){
	indexObj.tabStyle(data.index);
});